home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / thesrc10.zip / THE.H < prev    next >
C/C++ Source or Header  |  1992-08-12  |  18KB  |  535 lines

  1. /*
  2.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  3.  * Copyright (C) 1991,1992 Mark Hessling
  4.  *
  5.  * This program is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU General Public License as
  7.  * published by the Free Software Foundation; either version 2 of
  8.  * the License, or any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13.  * General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to:
  17.  *
  18.  *    The Free Software Foundation, Inc.
  19.  *    675 Mass Ave,
  20.  *    Cambridge, MA 02139 USA.
  21.  *
  22.  *
  23.  * If you make modifications to this software that you feel increases
  24.  * it usefulness for the rest of the community, please email the
  25.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  26.  * This software is going to be maintained and enhanced as deemed
  27.  * necessary by the community.
  28.  *
  29.  * Mark Hessling                     email: M.Hessling@itc.gu.edu.au
  30.  * 36 David Road                     Phone: +61 7 849 7731
  31.  * Holland Park                      Fax:   +61 7 875 7877
  32.  * QLD 4121
  33.  * Australia
  34.  */
  35. #ifdef __MSDOS__
  36. /*#define MEMTRACK*/
  37. #include <memtrack.h>
  38. #include <memory.h>
  39. #include <string.h>
  40. #include <process.h>
  41. #include <direct.h>
  42. #include <errno.h>
  43. #include <io.h>
  44. #include <ctype.h>
  45. #include <sys\types.h>
  46. #include <sys\stat.h>
  47. #define         W_OK          02
  48. #define         F_OK          00
  49. #define         R_OK          04
  50. /*#define touchline(WIN,START,NUM)       touchwin(WIN)*/
  51. #define PROTO
  52. #define SLASH '\\'
  53. #define STR_SLASH "\\"
  54. #define CURRENT_DIR "."
  55. #define FMODE (0)
  56. /*#define FMODE (S_IREAD | S_IWRITE)*/
  57. #endif
  58.  
  59. #ifdef __OS2__
  60. /*#define MEMTRACK*/
  61. #include <memtrack.h>
  62. #include <memory.h>
  63. #include <string.h>
  64. #include <process.h>
  65. #include <errno.h>
  66. #include <ctype.h>
  67. #include <sys\types.h>
  68. #include <sys\stat.h>
  69. #define         W_OK          02
  70. #define         F_OK          00
  71. #define         R_OK          04
  72. /*#define touchline(WIN,START,NUM)       touchwin(WIN)*/
  73. #define PROTO
  74. #define SLASH '\\'
  75. #define STR_SLASH "\\"
  76. #define CURRENT_DIR "."
  77. #define FMODE (0)
  78. /*#define FMODE (S_IREAD | S_IWRITE)*/
  79. #endif
  80.  
  81. #ifdef M_XENIX
  82. #include <ctype.h>
  83. #include <sys/types.h>
  84. #include <sys/stat.h>
  85. #include "mem.h"
  86. #include <memory.h>
  87. #include <string.h>
  88. #include <sys/file.h>
  89. #define         F_OK          00
  90. #define         W_OK          02
  91. #define         R_OK          04
  92. #define SLASH '/'
  93. #define STR_SLASH "/"
  94. #define CURRENT_DIR "."
  95. #define touchline(WIN,START,NUM)       touchwin(WIN)
  96. #define UNIX 1
  97. #endif
  98.  
  99. #ifdef SYSV386
  100. #include <ctype.h>
  101. #include <sys/types.h>
  102. #include <sys/stat.h>
  103. #include "memtrack.h"
  104. #include <memory.h>
  105. #include <string.h>
  106. #include <sys/file.h>
  107. #include <unistd.h>
  108. #define SLASH '/'
  109. #define STR_SLASH "/"
  110. #define CURRENT_DIR "."
  111. #define FMODE (0)
  112. #define UNIX 1
  113. #endif
  114.  
  115. #ifdef SUN
  116. #include "memtrack.h"
  117. #include <memory.h>
  118. #include <string.h>
  119. #include <sys/file.h>
  120. #include <sys/types.h>
  121. #include <sys/stat.h>
  122. #define SLASH '/'
  123. #define STR_SLASH "/"
  124. #define CURRENT_DIR "."
  125. /*#define FMODE (S_IRWXU | S_IRGRP | S_IROTH)*/
  126. #define FMODE (0)
  127. #ifdef BSD
  128. #define chtype short
  129. #endif
  130. #define UNIX 1
  131. #endif
  132.  
  133. #ifdef MINIX
  134. #include <string.h>
  135. #define short int
  136. #define CURRENT_DIR "."
  137. #define UNIX 1
  138. #endif
  139.  
  140. #ifdef VMS
  141. #include "memtrack.h"
  142. #include <string.h>
  143. #include <file.h>
  144. #include <types.h>
  145. #include <stat.h>
  146. #include <ctype.h>
  147. #define         W_OK          02
  148. #define         F_OK          00
  149. #define         R_OK          04
  150. #define SLASH ']'
  151. #define STR_SLASH "]"
  152. #define CURRENT_DIR "[]"
  153. /*#define FMODE (S_IRWXU | S_IRGRP | S_IROTH)*/
  154. #define FMODE (0)
  155. #ifdef BSD
  156. #define chtype short
  157. #endif
  158. #define touchline(WIN,START,NUM)       touchwin(WIN)
  159. /* #define isdigit(c)   (_ctype[(c) + 1] & 2)
  160. #define islower(c)   (_ctype[(c) + 1] & 8)
  161. #define isupper(c)   (_ctype[(c) + 1] & 4)*/
  162. #endif
  163.  
  164. #include <curses.h>
  165.  
  166. #ifndef A_NORMAL
  167. /* Various video attributes */
  168. #ifdef BSD
  169. #define A_STANDOUT      _STANDOUT    /* for compatability with old curses */
  170. #else
  171. #define A_STANDOUT      000000200000L
  172. #endif
  173. #define A_UNDERLINE     000000400000L
  174. #define A_REVERSE       000001000000L
  175. #define A_BLINK         000002000000L
  176. #define A_DIM           000004000000L
  177. #define A_BOLD          000010000000L
  178. #define A_ALTCHARSET    000100000000L
  179.  
  180. /* The next two are subject to change so don't depend on them */
  181. #define A_INVIS         000020000000L
  182. #define A_PROTECT       000040000000L
  183.  
  184. #define A_NORMAL        000000000000L
  185. #define A_ATTRIBUTES    037777600000L   /* 0xFFFF0000 */
  186. #define A_CHARTEXT      000000177777L   /* 0x0000FFFF */
  187. #endif
  188.  
  189. #ifndef max
  190. #define max(a,b)        (((a) > (b)) ? (a) : (b))
  191. #endif
  192.  
  193. #ifndef min
  194. #define min(a,b)        (((a) < (b)) ? (a) : (b))
  195. #endif
  196.  
  197. #ifndef getmaxy
  198. #ifdef VMS
  199. #define getmaxy(win)    ((win)->_max_y)
  200. #else
  201. #define getmaxy(win)    ((win)->_maxy)
  202. #endif
  203. #endif
  204.  
  205. #ifndef getmaxx
  206. #ifdef VMS
  207. #define getmaxx(win)    ((win)->_max_x)
  208. #else
  209. #define getmaxx(win)    ((win)->_maxx)
  210. #endif
  211. #endif
  212.  
  213. #define MAX_FILE_NAME 255
  214.  
  215. #define OFF             0
  216. #define ON              1
  217. #define NO              0
  218. #define YES             1
  219. #define NA              2
  220.  
  221. #ifndef OK
  222. #define OK              1
  223. #endif
  224.  
  225. #define ERROR         (-1)
  226. #define QUIT          (-2)
  227. #define SKIP          (-3)
  228. #define QUITOK        (-4)
  229. #define RAW_KEY       (128)
  230.  
  231. #define MAX_SCREENS         2             /* maximum number of screens*/
  232. #define VIEW_WINDOWS        5             /* number of windows per view */
  233. #define MAX_FILES           5             /* maximum number of open files */
  234. #define MAX_VIEWS           2             /* number of views per file */
  235. #define MAX_INT             65535         /* maximum size for integer */
  236. #define MAX_LONG            2147483001    /* maximum size for long */
  237. #define TARGET_ERROR        -2147483000   /* number returned as target error */
  238. #define TARGET_NOT_FOUND    -2147483001   /* number returned not found target */
  239. #define TOP_OF_FILE         "*** Top of File ***"
  240. #define BOTTOM_OF_FILE      "*** Bottom of File ***"
  241. #define DIRECTION_FORWARD   1
  242. #define DIRECTION_BACKWARD  (-1)
  243.  
  244. #define UNDEFINED_OPERAND (-1)
  245.  
  246. #define WINDOW_MAIN     0
  247. #define WINDOW_PREFIX   1
  248. #define WINDOW_COMMAND  2
  249. #define WINDOW_ARROW    3
  250. #define WINDOW_IDLINE   4
  251. #define WINDOW_FOOTING  5
  252. #define WINDOW_ERROR    6
  253. #define WINDOW_DIVIDER  7
  254.  
  255. #define PREFIX_WIDTH    6
  256.  
  257. #define CURRENT_VIEW              (vd_current)
  258. #define PREVIOUS_VIEW             (vd_current->prev)
  259. #define NEXT_VIEW                 (vd_current->next)
  260.  
  261. #define CURRENT_FILE              (vd_current->file_for_view)
  262. #define CURRENT_WINDOW            (vd_current->win[vd_current->current_window])
  263. #define CURRENT_WINDOW_MAIN       (vd_current->win[WINDOW_MAIN])
  264. #define CURRENT_WINDOW_PREFIX     (vd_current->win[WINDOW_PREFIX])
  265. #define CURRENT_WINDOW_COMMAND    (vd_current->win[WINDOW_COMMAND])
  266. #define CURRENT_WINDOW_ARROW      (vd_current->win[WINDOW_ARROW])
  267. #define CURRENT_WINDOW_IDLINE     (vd_current->win[WINDOW_IDLINE])
  268.  
  269. #define MARK_VIEW (vd_mark)
  270. #define MARK_FILE (vd_mark->file_for_view)
  271.  
  272. #define CURRENT_SCREEN (screen[current_screen])
  273. #define OTHER_SCREEN (screen[(current_screen == 0) ? 1 : 0])
  274.  
  275. struct line
  276.  {
  277.   unsigned short length;              /* number of characters in line */
  278.   unsigned char *line;                /* pointer to contents of line */
  279.   unsigned char display;              /* display level for each line */
  280.   struct line *prev;                  /* pointer to previous line */
  281.   struct line *next;                  /* pointer to next line */
  282.  };
  283. typedef struct line LINE;
  284.  
  285. struct targets
  286.  {
  287.   unsigned char *prefix;              /* pointer to target prefix */
  288.   short length;                       /* length of prefix */
  289.   unsigned char delim;                /* target delimiter */
  290.   char direction;                     /* search direction for target */
  291.  };
  292. typedef struct targets SEARCH_TARGET;
  293.  
  294. typedef struct
  295.  {
  296.   unsigned char autosave;             /* number of alterations before autosaving */
  297.   unsigned char eolout;               /* indicates how lines are terminated on output */
  298.   unsigned char status_row;           /* row on which status line is displayed */
  299.   unsigned char tabsout_on;           /* indicates if tabs to replace spaces on file */
  300.   unsigned char tabsout_num;          /* length of tab stops on file */
  301.   unsigned short autosave_alt;        /* number of alterations since last autosave */
  302.   unsigned short save_alt;            /* number of alterations since last save */
  303.   FILE *fp;                           /* file handle for this file */
  304.   unsigned char *fname;               /* file name */
  305.   unsigned char *fpath;               /* file path */
  306.   unsigned short fmode;               /* file mode of file */
  307.   LINE *first_line;                   /* pointer to first line */
  308.   LINE *curr_line;                    /* pointer to current line */
  309.   LINE *last_line;                    /* pointer to last line */
  310.   unsigned long  number_lines;        /* number of actual lines in file */
  311.   unsigned char file_views;           /* number of views of current file */
  312.  } FILE_DETAILS;
  313.  
  314. struct view_details
  315.  {
  316.   unsigned char cmd_line;             /* line where command line is displayed */
  317.   unsigned char command_row;          /* row on which command line is displayed */
  318.   unsigned char error_row;            /* row on which errors are to be displayed */
  319.   unsigned char tab_row;              /* row on which tab line is displayed */
  320.   unsigned char tab_on;               /* indicates if tab line is to be displayed */
  321.   unsigned char scale_row;            /* row on which scale row is displayed */
  322.   unsigned char scale_on;             /* indicates if scale is displayed */
  323.   unsigned char current_row;          /* row which is current row */
  324.   unsigned char prefix_on;            /* indicates if prefix is displayed */
  325.   unsigned char prefix_left;          /* indicates if prefix is displayed on left */
  326.   unsigned char case_enter;           /* indicates case of data entered */
  327.   unsigned char case_locate;          /* indicates case of data located */
  328.   unsigned char case_change;          /* indicates case of data changed */
  329.   unsigned char stay;                 /* indicates status of STAY */
  330.   unsigned char tabs;                 /* tab stop increments */
  331.   unsigned short verify_col;          /* left col for current verify */
  332.   unsigned short verify_start;        /* col of start of verify */
  333.   unsigned short verify_end;          /* col of end of verify */
  334.   unsigned short zone_start;          /* col of start of zone */
  335.   unsigned short zone_end;            /* col of end of zone */
  336.   long  current_line;                 /* line in file displayed on current row */
  337.   long  focus_line;                   /* line in file where cursor is */
  338.   long  mark_start_line;              /* first line to be marked */
  339.   long  mark_end_line;                /* last line to be marked */
  340.   WINDOW *win[VIEW_WINDOWS];          /* curses windows for the file contents */
  341.   unsigned char current_window;       /* current window for current file */
  342.   unsigned char previous_window;      /* previous window for current file */
  343.   FILE_DETAILS *file_for_view;        /* pointer to file structure */
  344.   struct view_details *prev;          /* pointer to previous view */
  345.   struct view_details *next;          /* pointer to next view */
  346.  };
  347. typedef struct view_details VIEW_DETAILS;
  348.  
  349. typedef struct
  350.  {
  351.   unsigned char origin_x;             /* top left corner of physical screen */
  352.   unsigned char origin_y;
  353.   unsigned char screen_rows;          /* physical rows */
  354.   unsigned char screen_cols;          /* physical cols */
  355.   unsigned char rows;                 /* rows in data window */
  356.   unsigned char cols;                 /* cols in data window */
  357.   unsigned char top_row;              /* start row of data window */
  358.   unsigned char top_col;              /* start col of data window */
  359.   VIEW_DETAILS *screen_view;          /* view being displayed in this screen */
  360.  } SCREEN_DETAILS;
  361.  
  362. #define STATUS_ROW         (screen_rows-1)
  363. #define COMMAND_ROW        (screen_rows-2)
  364. #define ERROR_ROW          1
  365. #define TAB_ROW            6
  366. #define TAB_ON             NO
  367. #define SCALE_ROW          6
  368. #define SCALE_ON           NO
  369. #define PREFIX_ON          YES
  370. #define CURSOR_ROW         COMMAND_ROW
  371. #define CURSOR_COL         5
  372. #define CURRENT_ROW_POS    0
  373. #define CURRENT_ROW        0
  374. #define ZONE_START         1
  375. #define ZONE_END           MAX_INT
  376.  
  377. #define CASE_MIXED         'M'
  378. #define CASE_UPPER         'U'
  379. #define CASE_LOWER         'L'
  380. #define CASE_IGNORE        'I'
  381. #define CASE_RESPECT       'R'
  382.  
  383. #ifndef FILE_NORMAL
  384. #define FILE_NORMAL        0
  385. #endif
  386.  
  387. #ifndef FILE_READONLY
  388. #define FILE_READONLY      1
  389. #endif
  390.  
  391. #ifndef FILE_NEW
  392. #define FILE_NEW          99
  393. #endif
  394.  
  395. #define ADDCHAR            0
  396. #define INSCHAR            1
  397.  
  398. #ifndef getbegyx
  399. #define getbegyx(win,y,x)       (y = (win)->_begy, x = (win)->_begx)
  400. #endif
  401.  
  402. /*---------------------- function definitions -------------------------*/
  403. #ifdef PROTO
  404. void set_defaults(void);
  405. short defaults_for_first_file(void);
  406. short get_profile(unsigned char *);
  407. short get_file(unsigned char *);
  408. LINE *read_file(FILE *,LINE *,unsigned char *);
  409. void exit_clean(short);
  410. void display_error(unsigned short,unsigned char *);
  411. LINE *ll_add(LINE *,LINE *,unsigned short);
  412. LINE *ll_del(LINE *,LINE *,char);
  413. LINE *ll_find(LINE *,unsigned long);
  414. void ll_free(LINE *);
  415. LINE *add_line(LINE *,LINE *,unsigned char *,unsigned short);
  416. VIEW_DETAILS *vll_add(VIEW_DETAILS *,VIEW_DETAILS *,unsigned short);
  417. VIEW_DETAILS *vll_del(VIEW_DETAILS *,VIEW_DETAILS *,char);
  418. void show_page(void);
  419. void show_one_row(unsigned char *,unsigned short,unsigned short,LINE *);
  420. char *meminschr(char *,unsigned char,short,short,short);
  421. char *meminsmem(char *,char *,short,short,short,short);
  422. char *memdelchr(char *,short,short,short);
  423. short mempos(unsigned char *,short,unsigned char *,short);
  424. short memposi(unsigned char *,short,unsigned char *,short);
  425. short memcmpi(unsigned char *,unsigned char *,short);
  426. short memne(unsigned char *,unsigned char,short);
  427. long find_string(long,short *,char *,short,char,char,char);
  428. void increment_alt(void);
  429. unsigned char *new_filename(unsigned char *,unsigned char *,
  430.                             unsigned char *,unsigned char *);
  431. short splitpath(unsigned char *);
  432. void put_char(WINDOW *,chtype,char);
  433. void adjust_marked_block(char,long,long);
  434. void add_to_recovery_list(char *,int);
  435. int insert_new_line(unsigned char *,int,long,bool);
  436. void get_from_recovery_list(int);
  437. int parse_colours(char *,chtype *,chtype *,chtype *);
  438. void set_colour(int,chtype,chtype,chtype);
  439. #else
  440. void set_defaults();
  441. short defaults_for_first_file();
  442. short get_profile();
  443. short get_file();
  444. LINE *read_file();
  445. void exit_clean();
  446. void display_error();
  447. LINE *ll_add();
  448. LINE *ll_del();
  449. LINE *ll_find();
  450. void ll_free();
  451. LINE *add_line();
  452. VIEW_DETAILS *vll_add();
  453. VIEW_DETAILS *vll_del();
  454. void show_page();
  455. void show_one_row();
  456. char *meminschr();
  457. char *meminsmem();
  458. char *memdelchr();
  459. short mempos();
  460. short memposi();
  461. short memcmpi();
  462. short memne();
  463. long find_string();
  464. void increment_alt();
  465. unsigned char *new_filename();
  466. short splitpath();
  467. void put_char();
  468. void adjust_marked_block();
  469. void add_to_recovery_list();
  470. int insert_new_line();
  471. void get_from_recovery_list();
  472. int parse_colours();
  473. void set_colour();
  474. #endif
  475. /*---------------------- system specific redefines --------------------*/
  476. #ifdef VAX
  477. #define     wattrset     wsetattr
  478. #define     A_REVERSE    _REVERSE
  479. #define     A_BOLD       _BOLD
  480. #endif
  481. /*---------------------- global parameters ----------------------------*/
  482. #define EOLOUT_LF                0
  483. #define EOLOUT_CRLF              1
  484. /*---------------------- attribute defines ----------------------------*/
  485. #define ATTR_FILEAREA   0
  486. #define ATTR_CURLINE    1
  487. #define ATTR_BLOCK      2
  488. #define ATTR_CBLOCK     3
  489. #define ATTR_CMDLINE    4
  490. #define ATTR_IDLINE     5
  491. #define ATTR_MSGLINE    6
  492. #define ATTR_ARROW      7
  493. #define ATTR_PREFIX     8
  494. #define ATTR_PENDING    9
  495. #define ATTR_SCALE     10
  496. #define ATTR_TOFEOF    11
  497. #define ATTR_CTOFEOF   12
  498. #define ATTR_TABLINE   13
  499. #define ATTR_SHADOW    14
  500. #define ATTR_STATAREA  15
  501. #define ATTR_DIVIDER   16
  502. #define ATTR_MAX       17
  503.  
  504. #ifdef MAIN
  505. /*---------------------------------------------------------------------*/
  506. /* Following is  for colour support.                                   */
  507. /*---------------------------------------------------------------------*/
  508.  
  509. chtype colour[ATTR_MAX];
  510. chtype save_fg[ATTR_MAX];
  511. chtype save_bg[ATTR_MAX];
  512. chtype save_mod[ATTR_MAX];
  513.  
  514. char tabkey_insert='C';
  515. char tabkey_overwrite='T';
  516. unsigned short mark_start_col=0;
  517. unsigned short mark_end_col;
  518. short max_line_length=2048;
  519.  
  520. #else
  521.  
  522. extern chtype colour[ATTR_MAX];
  523. extern chtype save_fg[ATTR_MAX];
  524. extern chtype save_bg[ATTR_MAX];
  525. extern chtype save_mod[ATTR_MAX];
  526.  
  527. extern char tabkey_insert;
  528. extern char tabkey_overwrite;
  529. extern unsigned short mark_start_col;
  530. extern unsigned short mark_end_col;
  531. extern short max_line_length;
  532. #endif
  533. #define MAX_LINE_LENGTH     max_line_length /* maximum size for a line */
  534.  
  535.